# Used by wechat gems, do not rename WechatSession to other name,
# Feel free to inherit from other class like ActiveModel::Model
class WechatSession
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Attributes::Dynamic
  field :openid, type: String
  field :access_token, type: String
  field :refresh_token, type: String
  field :scope, type: String
  field :customer_id, type: String #绑定用户id
  field :customer_mobile, type: String, default: '' #绑定用户手机号
  validates :openid, presence: true, uniqueness: true
  # serialize :hash_store, Hash
  #
  # # called by wechat gems when user request session
  # def self.find_or_initialize_session(request_message)
  #   find_or_initialize_by(openid: request_message[:from_user_name])
  # end
  #
  # # called by wechat gems after response Techent server at controller#create
  # def save_session(_response_message)
  #   touch unless new_record? # Always refresh updated_at even no change
  #   save!
  # end


  #获取微信业务id
  def business_id
    "wechat_#{self.id.to_s}"
  end

end
